package com.tangji.signaltower.container;

import com.tangji.signaltower.bean.MarketDataEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: yujianfu (mr.vencnet@gmail.com)
 * Date: 2020-07-23
 * Time: 10:24
 */
public class DataContainer {

    private static final Logger logger = LoggerFactory.getLogger(DataContainer.class);

    private String productType;

    private MarketDataEntity lastData = null;

    private List<MarketDataEntity> lastDataList;

    public DataContainer() {
    }

    public DataContainer(String productType, MarketDataEntity lastData) {
        this.productType = productType;
        this.lastData = lastData;
        this.lastDataList = new ArrayList<>();
        this.lastDataList.add(lastData);
    }

    public DataContainer updateLastData(MarketDataEntity marketDataEntity) {
        this.lastData = marketDataEntity;
        if (this.lastDataList.size() < 10) {
            this.addLastDataList(marketDataEntity);
        }
        return this;
    }


    public MarketDataEntity getLastData() {
        return lastData;
    }

    public List<MarketDataEntity> getLastDataList() {
        return lastDataList;
    }

    public DataContainer addLastDataList(MarketDataEntity marketDataEntity) {
        this.lastDataList.add(marketDataEntity);
        return this;
    }

    public DataContainer resetDataList() {
        this.lastDataList = new ArrayList<>();
        return this;
    }

    /**
     * 全部采用引用替换的方式 避免造成值混乱问题
     *
     * @param marketDataEntity
     * @return
     */
    public void addDataToList(MarketDataEntity marketDataEntity) {
        this.lastData = marketDataEntity;
    }
}
